﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Vowei.Core.Models;

namespace Vowei.Data.Models
{
    public partial class Permission : IPermission
    {
        public Permission()
        {
            ID = Guid.NewGuid();
        }

        public virtual bool Authorized(string permission)
        {
            return string.CompareOrdinal(Title, permission) == 0;
        }

        public int CompareTo(IPermission another)
        {
            throw new NotImplementedException();
        }

        public int CompareTo(string permission)
        {
            throw new NotImplementedException();
        }
    }

    public class PermissionComparer : IComparer<Permission>
    {
        public int Compare(Permission x, Permission y)
        {
            return x.ID.CompareTo(y.ID);
        }
    }

    public class PermissionEqualityComparer : IEqualityComparer<Permission>
    {
        public bool Equals(Permission x, Permission y)
        {
            if (x == null && y == null)
                return true;
            else if (x != null && y == null)
                return false;
            else if (x == null && y != null)
                return false;
            else
                return x.ID.CompareTo(y.ID) == 0;
        }

        public int GetHashCode(Permission obj)
        {
            return obj.GetHashCode();
        }
    }

}
